package com.qd;

import cn.hutool.core.thread.ExecutorBuilder;
import cn.hutool.core.thread.RejectPolicy;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author sjk
 */
@SpringBootApplication
@EnableTransactionManagement
@EnableAsync
@EnableScheduling
@EnableRetry
@MapperScan(value = {"com.qd.system.mapper", "com.qd.panda.mapper", "com.cdqidi.core.weixinmanager.mapper", "com.qd.thirdpart.mapper", "com.qd.pay.mapper","com.qd.flow.mapper"})
public class AuthAdminApplication {

    /**
     * 线程池，主要用于处理远程调用
     * 获取费用以及计算费用
     *
     * @return ThreadPoolExecutor
     */
    @Bean(name = "strokeThreadPoolExecutor")
    public ThreadPoolExecutor getThreadPoolExecutor() {
        return ExecutorBuilder.create()
                .setCorePoolSize(5)
                .setMaxPoolSize(30)
                .setWorkQueue(new ArrayBlockingQueue<>(5000))
                .setHandler(RejectPolicy.ABORT.getValue())
                .setAllowCoreThreadTimeOut(true)
                .setKeepAliveTime(30, TimeUnit.MINUTES)
                .setThreadFactory(runnable -> {
                    Thread thread = new Thread(runnable);
                    thread.setName("panda-park-stroke-");
                    return thread;
                }).build();
    }

    @Bean
    public ExitCodeGenerator exitCodeGenerator() {
        return () -> 42;
    }

    public static void main(String[] args) {
        SpringApplication.run(AuthAdminApplication.class, args);
    }
}
